using System;
using System.Collections.Generic;
using OneSignalPush.MiniJSON;
using UnityEngine;

public class GameControllerExample : MonoBehaviour
{
	private static string extraMessage;

	private void Start()
	{
		extraMessage = null;
	}

	private void OneSignal_subscriptionObserver(OSSubscriptionStateChanges stateChanges)
	{
		Debug.Log("stateChanges: " + stateChanges);
		Debug.Log("stateChanges.to.userId: " + stateChanges.to.userId);
		Debug.Log("stateChanges.to.subscribed: " + stateChanges.to.subscribed);
	}

	private void OneSignal_permissionObserver(OSPermissionStateChanges stateChanges)
	{
		Debug.Log("stateChanges.to.status: " + stateChanges.to.status);
	}

	private static void HandleNotificationReceived(OSNotification notification)
	{
		OSNotificationPayload payload = notification.payload;
		string body = payload.body;
		MonoBehaviour.print("GameControllerExample:HandleNotificationReceived: " + body);
		MonoBehaviour.print("displayType: " + notification.displayType);
		extraMessage = "Notification received with text: " + body;
		Dictionary<string, object> additionalData = payload.additionalData;
		if (additionalData == null)
		{
			Debug.Log("[HandleNotificationReceived] Additional Data == null");
		}
		else
		{
			Debug.Log("[HandleNotificationReceived] message " + body + ", additionalData: " + Json.Serialize(additionalData));
		}
	}

	public static void HandleNotificationOpened(OSNotificationOpenedResult result)
	{
		OSNotificationPayload payload = result.notification.payload;
		string body = payload.body;
		string actionID = result.action.actionID;
		MonoBehaviour.print("GameControllerExample:HandleNotificationOpened: " + body);
		extraMessage = "Notification opened with text: " + body;
		Dictionary<string, object> additionalData = payload.additionalData;
		if (additionalData == null)
		{
			Debug.Log("[HandleNotificationOpened] Additional Data == null");
		}
		else
		{
			Debug.Log("[HandleNotificationOpened] message " + body + ", additionalData: " + Json.Serialize(additionalData));
		}
		if (actionID != null)
		{
			extraMessage = "Pressed ButtonId: " + actionID;
		}
	}

	private void OnGUI()
	{
		GUIStyle gUIStyle = new GUIStyle("button");
		gUIStyle.fontSize = 30;
		GUIStyle gUIStyle2 = new GUIStyle("box");
		gUIStyle2.fontSize = 30;
		GUI.Box(new Rect(10f, 10f, 390f, 340f), "Test Menu", gUIStyle2);
		if (GUI.Button(new Rect(60f, 80f, 300f, 60f), "SendTags", gUIStyle))
		{
			Dictionary<string, string> dictionary = new Dictionary<string, string>();
			dictionary.Add("UnityTestKey2", "value2");
			dictionary.Add("UnityTestKey3", "value3");
		}
		if (GUI.Button(new Rect(60f, 170f, 300f, 60f), "GetIds", gUIStyle))
		{
		}
		if (GUI.Button(new Rect(60f, 260f, 300f, 60f), "TestNotification", gUIStyle))
		{
			extraMessage = "Waiting to get a OneSignal userId. Uncomment OneSignal.SetLogLevel in the Start method if it hangs here to debug the issue.";

		}
		if (extraMessage != null)
		{
			gUIStyle2.alignment = TextAnchor.UpperLeft;
			gUIStyle2.wordWrap = true;
			GUI.Box(new Rect(10f, 390f, Screen.width - 20, Screen.height - 400), extraMessage, gUIStyle2);
		}
	}
}
